home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / +system+ / tools / gui / bgui.lha / bgui / Examples / Source / IDCMPHook.c < prev    next >
C/C++ Source or Header  |  2000-02-27  |  6KB  |  171 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Attic/IDCMPHook.c,v 1.1.2.2 1999/02/19 05:03:54 mlemos Exp $
  3.  *
  4.  * IDCMPHook.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * $Log: IDCMPHook.c,v $
  12.  * Revision 1.1.2.2  1999/02/19 05:03:54  mlemos
  13.  * Added support to build with Storm C.
  14.  *
  15.  * Revision 1.1.2.1  1998/02/28 17:45:20  mlemos
  16.  * Ian sources
  17.  *
  18.  *
  19.  */
  20.  
  21. /* Execute me to compile with DICE V3.0
  22. dcc IDCMPHook.c -proto -mi -ms -mRR -lbgui
  23. quit
  24. */
  25.  
  26. #include "DemoCode.h"
  27.  
  28. /*
  29. **      Object ID.
  30. **/
  31. #define ID_QUIT                 1
  32.  
  33. /*
  34. **      "tick" counter for the hook.
  35. **/
  36. UBYTE   Ticks = 0;
  37.  
  38. /*
  39. **      Simple example of the hook code.
  40. **/
  41. #ifdef __STORM__
  42. VOID SAVEDS ASM
  43. #else
  44. SAVEDS ASM VOID
  45. #endif
  46. hookFunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct IntuiMessage *imsg )
  47. {
  48.         struct Window                   *wptr = NULL;
  49.  
  50.         /*
  51.         **      This hook is a simple IDCMP_INTUITICKS hook.
  52.         **      More complex hooks can receive several message
  53.         **      types depending on the setting of the
  54.         **      WINDOW_IDCMPHookBits attribute.
  55.         **
  56.         **      Simply beep the screen
  57.         **      every two seconds or so
  58.         **      while the window is active.
  59.         **/
  60.         if ( Ticks == 20 ) {
  61.                 Ticks = 0;
  62.                 /*
  63.                 **      Only flash the screen on which
  64.                 **      the window is located.
  65.                 **/
  66.                 GetAttr( WINDOW_Window, obj, ( ULONG * )&wptr );
  67.                 if ( wptr )
  68.                         DisplayBeep( wptr->WScreen );
  69.         }
  70.         Ticks++;
  71. }
  72.  
  73.  
  74. /*
  75. **      The hook structure.
  76. **
  77. ** typedef unsigned long (*HOOKFUNC)();
  78. **/
  79. struct Hook idcmpHook = { NULL, NULL, (HOOKFUNC)hookFunc, NULL, NULL };
  80.  
  81. VOID StartDemo( void )
  82. {
  83.         struct Window           *window;
  84.         Object                  *WO_Window, *GO_Quit;
  85.         ULONG                    signal = 0, rc;
  86.         BOOL                     running = TRUE;
  87.  
  88.         /*
  89.         **      Create the window object.
  90.         **/
  91.         WO_Window = WindowObject,
  92.                 WINDOW_Title,           "IDCMPHook Demo",
  93.                 WINDOW_SizeGadget,      FALSE,
  94.                 WINDOW_RMBTrap,         TRUE,
  95.                 WINDOW_IDCMP,           IDCMP_INTUITICKS,
  96.                 WINDOW_IDCMPHookBits,   IDCMP_INTUITICKS,
  97.                 WINDOW_IDCMPHook,       &idcmpHook,
  98.                 WINDOW_AutoAspect,      TRUE,
  99.                 WINDOW_MasterGroup,
  100.                         /*
  101.                         **      A simple vertical group
  102.                         **      containing a descriptive text
  103.                         **      and a "Quit" button.
  104.                         **/
  105.                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  106.                                 StartMember, InfoFixed( NULL, "\33cThis small demo has a IDCMP-hook\n"
  107.                                                               "installed which will flash the\n"
  108.                                                               "display every two seconds while the\n"
  109.                                                               "window is active.", NULL, 4 ), EndMember,
  110.                                 StartMember,
  111.                                         HGroupObject,
  112.                                                 VarSpace( DEFAULT_WEIGHT ),
  113.                                                 StartMember, GO_Quit  = KeyButton( "_Quit",  ID_QUIT  ), EndMember,
  114.                                                 VarSpace( DEFAULT_WEIGHT ),
  115.                                         EndObject,
  116.                                 EndMember,
  117.                         EndObject,
  118.         EndObject;
  119.  
  120.         /*
  121.         **      Object created OK?
  122.         **/
  123.         if ( WO_Window ) {
  124.                 /*
  125.                 **      Assign a key to the button.
  126.                 **/
  127.                 if ( GadgetKey( WO_Window, GO_Quit,  "q" )) {
  128.                         /*
  129.                         **      try to open the window.
  130.                         **/
  131.                         if ( window = WindowOpen( WO_Window )) {
  132.                                 /*
  133.                                 **      Obtain it's wait mask.
  134.                                 **/
  135.                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  136.                                 /*
  137.                                 **      Event loop...
  138.                                 **/
  139.                                 do {
  140.                                         Wait( signal );
  141.                                         /*
  142.                                         **      Handle events.
  143.                                         **/
  144.                                         while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  145.                                                 /*
  146.                                                 **      Evaluate return code.
  147.                                                 **/
  148.                                                 switch ( rc ) {
  149.  
  150.                                                         case    WMHI_CLOSEWINDOW:
  151.                                                         case    ID_QUIT:
  152.                                                                 running = FALSE;
  153.                                                                 break;
  154.                                                 }
  155.                                         }
  156.                                 } while ( running );
  157.                         } else
  158.                                 Tell( "Could not open the window\n" );
  159.                 } else
  160.                         Tell( "Could not assign gadget key\n" );
  161.                 /*
  162.                 **      Disposing of the window object will
  163.                 **      also close the window if it is
  164.                 **      already opened and it will dispose of
  165.                 **      all objects attached to it.
  166.                 **/
  167.                 DisposeObject( WO_Window );
  168.         } else
  169.                 Tell( "Unable to create the window object\n" );
  170. }
  171.